home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Nebula 1
/
Nebula One.iso
/
Mail
/
pine3.92
/
pine
/
osdep
/
debuging.os2
< prev
next >
Wrap
Text File
|
1996-03-14
|
3KB
|
110 lines
#line 2 "osdep/debuging.os2"
#ifdef DEBUG
/*----------------------------------------------------------------------
Initialize debugging - open the debug log file
Args: none
Result: opens the debug logfile for dprints
----*/
void
init_debug()
{
char *p;
char filename[MAXPATH+1];
if(!debug)
return;
/*
* we can't assume anything about root or home dirs, so
* just plunk it down in the same place as the pinerc
*/
if(ps_global->pinerc)
sprintf(filename, "%.*s%s",
last_cmpnt(ps_global->pinerc) - ps_global->pinerc,
ps_global->pinerc, DEBUGFILE);
else if((p=getenv("PINEHOME"))!=NULL || (p=getenv("HOME"))!=NULL)
build_path(filename, p, DEBUGFILE);
else
strcpy(filename, DEBUGFILE);
unlink(filename);
debugfile = fopen(filename, "w");
if(debugfile != NULL){
time_t now = time((time_t *)0);
if(debug > 7)
setbuf(debugfile, NULL);
dprint(1, (debugfile, "Debug output of the Pine program (at debug"));
dprint(1, (debugfile, " level %d). Version %s\n%s\n",
debug, pine_version, ctime(&now)));
}
}
void
save_debug_on_crash(dfile)
FILE *dfile;
{
char *crashname = CRASHFILE;
char *filename = DEBUGFILE;
int status;
char msg[256];
time_t now = time((time_t *)0);
fprintf(dfile, "\nsave_debug_on_crash: Version %s: debug level %d\n",
pine_version, debug);
fprintf(dfile, "\n : %s\n", ctime(&now));
fprintf(dfile, "\nAttempting to save debug file to %s\n", crashname);
fclose(dfile);
unlink (crashname);
status = rename (filename, crashname);
#ifdef _WINDOWS
sprintf (msg, "Pine debugging information saved in file: %s",
status == 0 ? crashname : filename);
mswin_messagebox (msg);
#endif
}
#define CHECK_EVERY_N_TIMES 100
#define MAX_DEBUG_FILE_SIZE 200000L
/*
* This is just to catch runaway Pines that are looping spewing out
* debugging (and filling up a file system). The stop doesn't have to be
* at all precise, just soon enough to hopefully prevent filling the
* file system. If the debugging level is high (9 for now), then we're
* presumably looking for some problem, so don't truncate.
*/
int
do_debug(debug_fp)
FILE *debug_fp;
{
static int counter = CHECK_EVERY_N_TIMES;
static int ok = 1;
long filesize;
if(debug < 9 && ok && --counter <= 0){
if((filesize = fp_file_size(debug_fp)) != -1L)
ok = (unsigned long)filesize < (unsigned long)MAX_DEBUG_FILE_SIZE;
counter = CHECK_EVERY_N_TIMES;
if(!ok){
fprintf(debug_fp, "\n\n --- No more debugging ---\n");
fprintf(debug_fp,
" (debug file growing too large - over %ld bytes)\n\n",
MAX_DEBUG_FILE_SIZE);
fflush(debug_fp);
}
}
return(ok);
}
#endif /* DEBUG */